Skip to content

fix: add tool count validation with env-configurable MAX_TOOLS - #5

Closed
lireno wants to merge 1 commit into
mainfrom
fix/tool-count-validation
Closed

fix: add tool count validation with env-configurable MAX_TOOLS#5
lireno wants to merge 1 commit into
mainfrom
fix/tool-count-validation

Conversation

@lireno

@lireno lireno commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Fixes aipotheosis-labs#337. Prevents OpenAI API errors when too many functions are selected. Adds env-configurable MAX_TOOLS, better error messaging, and tests. Closes aipotheosis-labs#337.

Improvements over PR aipotheosis-labs#604

  • Env-var configurability for MAX_TOOLS via SERVER_MAX_TOOLS
  • Better error messages with actual count, limit, and guidance
  • Comprehensive tests covering boundary conditions and edge cases
  • Proper ACIException subclass consistent with codebase patterns

…nses (aipotheosis-labs#337)

Add MAX_TOOLS validation in the /chat route and openai_chat_stream to
prevent cryptic OpenAI API errors when too many functions are selected.
OpenAI's Responses API has undocumented limits (~128 tools or ~200k
tokens of tool definitions). Exceeding them returns an unhelpful APIError
that surfaces as a 500, causing empty AI responses.

Improvements over PR aipotheosis-labs#604:
- MAX_TOOLS is configurable via SERVER_AGENT_MAX_TOOLS env var (default 64)
- Error message lists affected app names so users know which apps to disable
- Error message mentions the env var so operators can adjust the limit
- Error message truncates long app lists (>10 apps)
- Added unit tests for validate_tool_count covering under/at/over limit,
  app name extraction, env var reference, and empty tools edge case

Closes aipotheosis-labs#337
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lireno
lireno force-pushed the fix/tool-count-validation branch from ba889b0 to 24bb848 Compare June 2, 2026 18:11
@lireno lireno closed this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI returns empty response when multiple GMAIL functions are selected

1 participant